package com.yifeng.repo.controller.excel.loader.worker;

import com.gomcarter.frameworks.base.common.AssertUtils;
import com.yifeng.repo.tookit.oss.OssFileClient;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by daibing on 2024/2/9.
 */
@Slf4j
public class ExcelLoaderOssWorker {
    private final OssFileClient ossFileClient;
    private final boolean nonOss;

    /**
     * 支持没有oss的业务场景
     */
    public ExcelLoaderOssWorker() {
        this.ossFileClient = null;
        this.nonOss = true;
    }

    public ExcelLoaderOssWorker(OssFileClient ossFileClient) {
        this.ossFileClient = ossFileClient;
        this.nonOss = false;
    }

    public String uploadFile(String path, String localFilePath) {
        if (nonOss) {
            log.info("uploadFile is nothing to do, return {}", localFilePath);
            return localFilePath;
        }
        AssertUtils.notNull(ossFileClient, "未设置ossFileClient客户端！");
        return ossFileClient.uploadFile(path, localFilePath);
    }
}
